package com.adee.nowcoder.huawei;

import java.util.Scanner;

public class T014_HJ14 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            int len = Integer.parseInt(in.nextLine());
            String[] arr = new String[len];
            for(int i = 0; i < len; i++) {
                arr[i] = in.nextLine();
            }
            // 排序
            for(int i = arr.length-1; i >= 0; i--) {
                for(int j = 0; j < i; j++) {

                    if(compare(arr[j], arr[j+1]) > 0) {
                        String tmp = arr[j];
                        arr[j] = arr[j+1];
                        arr[j+1] = tmp;
                    }
                }
            }
            for(String s : arr) {
                System.out.println(s);
            }
        }
    }
    // a - b
    static int compare(String a, String b) {
        String a1 = a.toLowerCase();
        String b1 = b.toLowerCase();
        int lena = a.length();
        int lenb = b.length();
        int len = lena > lenb ? lenb : lena;
        for (int i = 0; i < len; i++) {
            if(a1.charAt(i) > b1.charAt(i)) return 1;
            else if(a1.charAt(i) < b1.charAt(i)) return -1;
        }
        return lena - lenb;
    }
}
